package com.specter.serv.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.specter.mvc.model.dao.BaseDao;
import com.specter.serv.service.UserDetailService;
import com.specter.sure.core.Authorized;
import com.specter.sure.core.Permission;

/**
 * Note:通过数据库集成访问权限系统
 * 
 * @author Liang.Wang
 * @version Jul 23, 2014
 */
@Transactional
@Service("SP-FRDB")
public class UserDetailServiceImpl implements UserDetailService {
	private String prefix = "com.specter.serv.entity.User";
	private @Autowired BaseDao baseDao;

	@Value("${specter.app.application.name}")
	private String appCode;

	@Override
	public Authorized userinfo(String loginId) {
		Authorized user = baseDao.selectOne(prefix + "select_user_info", loginId);
		user.setPermissions(this.permission(loginId));
		return user;
	}

	@Override
	public Permission[] permission(String userinfo) {
		List<Permission> perm = baseDao.select(prefix + "select_user_perm", userinfo);
		return perm.toArray(Permission[]::new);
	}

	@Override
	public boolean validate(String userinfo) {
		return true;
	}

	@Override
	public Authorized register(String userinfo) {
		throw new UnsupportedOperationException("Unimplemented method 'register'");
	}

}
